Tables [dbo].[CampaignParticipation]
Properties
PropertyValue
Row Count0
Created10:31:15 AM Tuesday, March 02, 2010
Last Modified1:20:14 PM Thursday, February 23, 2012
Columns
NameData TypeMax Length (Bytes)Allow Nulls
Cluster Primary Key PK_CampaignParticipation: CampaignParticipationKeyCampaignParticipationKeyuniqueidentifier16
No
Foreign Keys FK_CampaignParticipation_CampaignMain: [dbo].[CampaignMain].CampaignKeyIndexes IX_CampaignParticipation_CampaignKey: CampaignKeyCampaignKeyuniqueidentifier16
No
Indexes IX_CampaignParticipation_RespondentUserKey: RespondentUserKeyRespondentUserKeyuniqueidentifier16
No
Foreign Keys FK_CampaignParticipation_ResponseTypeRef: [dbo].[ResponseTypeRef].ResponseTypeCodeIndexes IX_CampaignParticipation_ResponseTypeCode: ResponseTypeCodeResponseTypeCodeint4
No
Foreign Keys FK_CampaignParticipation_UserMain_CreatedBy: [dbo].[UserMain].CreatedByUserKeyIndexes IX_CampaignParticipation_CreatedByUserKey: CreatedByUserKeyCreatedByUserKeyuniqueidentifier16
No
CreatedOndatetime8
No
Foreign Keys FK_CampaignParticipation_UserMain_UpdatedBy: [dbo].[UserMain].UpdatedByUserKeyIndexes IX_CampaignParticipation_UpdatedByUserKey: UpdatedByUserKeyUpdatedByUserKeyuniqueidentifier16
No
UpdatedOndatetime8
No
MarkedForDeleteOndatetime8
Yes
Foreign Keys FK_CampaignParticipation_SourceCode: [dbo].[SourceCode].OptOutSourceCodeKeyIndexes IX_CampaignParticipation_OptOutSourceCodeKey: OptOutSourceCodeKeyOptOutSourceCodeKeyuniqueidentifier16
Yes
OptedOutOndatetime8
Yes
Indexes Indexes
NameColumnsUnique
Cluster Primary Key PK_CampaignParticipation: CampaignParticipationKeyPK_CampaignParticipationCampaignParticipationKey
Yes
IX_CampaignParticipation_CampaignKeyCampaignKey
IX_CampaignParticipation_CreatedByUserKeyCreatedByUserKey
IX_CampaignParticipation_OptOutSourceCodeKeyOptOutSourceCodeKey
IX_CampaignParticipation_RespondentUserKeyRespondentUserKey
IX_CampaignParticipation_ResponseTypeCodeResponseTypeCode
IX_CampaignParticipation_UpdatedByUserKeyUpdatedByUserKey
Triggers Triggers
NameANSI Nulls OnQuoted Identifier OnOn
asi_CampaignParticipation_Insert
Yes
Yes
After Insert
asi_CampaignParticipation_Update
Yes
Yes
After Update
Foreign Keys Foreign Keys
NameColumns
FK_CampaignParticipation_CampaignMainCampaignKey->[dbo].[CampaignMain].[CampaignKey]
FK_CampaignParticipation_ResponseTypeRefResponseTypeCode->[dbo].[ResponseTypeRef].[ResponseTypeCode]
FK_CampaignParticipation_SourceCodeOptOutSourceCodeKey->[dbo].[SourceCode].[SourceCodeKey]
FK_CampaignParticipation_UserMain_CreatedByCreatedByUserKey->[dbo].[UserMain].[UserKey]
FK_CampaignParticipation_UserMain_UpdatedByUpdatedByUserKey->[dbo].[UserMain].[UserKey]
SQL Script
CREATE TABLE [dbo].[CampaignParticipation]
(
[CampaignParticipationKey] [uniqueidentifier] NOT NULL,
[CampaignKey] [uniqueidentifier] NOT NULL,
[RespondentUserKey] [uniqueidentifier] NOT NULL,
[ResponseTypeCode] [int] NOT NULL,
[CreatedByUserKey] [uniqueidentifier] NOT NULL,
[CreatedOn] [datetime] NOT NULL,
[UpdatedByUserKey] [uniqueidentifier] NOT NULL,
[UpdatedOn] [datetime] NOT NULL,
[MarkedForDeleteOn] [datetime] NULL,
[OptOutSourceCodeKey] [uniqueidentifier] NULL,
[OptedOutOn] [datetime] NULL
) ON [PRIMARY]

GO
CREATE TRIGGER [dbo].[asi_CampaignParticipation_Insert]
    ON  [dbo].[CampaignParticipation]
    FOR INSERT
AS
BEGIN
    SET NOCOUNT ON;
    -- Fail the transaction if any inserted key is not in
    -- either the ContactMain or Prospect tables
    IF EXISTS(SELECT CampaignParticipationKey from inserted)
       AND NOT EXISTS(SELECT cm.ContactKey from ContactMain cm INNER JOIN inserted i ON cm.ContactKey=i.RespondentUserKey)
       AND NOT EXISTS(SELECT p.ProspectKey from Prospect p INNER JOIN inserted i ON p.ProspectKey=i.RespondentUserKey)
    BEGIN
        RAISERROR(N'One or more CampaignParticipation.RespondentUserKeys in being inserted reference neither a ContactKey nor a ProspectKey', 16, 1)
        ROLLBACK TRAN
    END
END

GO
CREATE TRIGGER [dbo].[asi_CampaignParticipation_Update]
    ON  [dbo].[CampaignParticipation]
    FOR UPDATE
AS
BEGIN
    SET NOCOUNT ON;
    IF NOT UPDATE(RespondentUserKey)
    RETURN
    -- Fail the transaction if any inserted key is not in
    -- either the ContactMain or Prospect tables
    IF NOT EXISTS(SELECT cm.ContactKey from ContactMain cm INNER JOIN inserted i ON cm.ContactKey=i.RespondentUserKey)
       AND NOT EXISTS(SELECT p.ProspectKey from Prospect p INNER JOIN inserted i ON p.ProspectKey=i.RespondentUserKey)
    BEGIN
        RAISERROR(N'One or more CampaignParticipation.RespondentUserKeys in being inserted reference neither a ContactKey nor a ProspectKey', 16, 1)
        ROLLBACK TRAN
    END
END

GO
ALTER TABLE [dbo].[CampaignParticipation] ADD CONSTRAINT [PK_CampaignParticipation] PRIMARY KEY CLUSTERED ([CampaignParticipationKey]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_CampaignParticipation_CampaignKey] ON [dbo].[CampaignParticipation] ([CampaignKey]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_CampaignParticipation_CreatedByUserKey] ON [dbo].[CampaignParticipation] ([CreatedByUserKey]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_CampaignParticipation_OptOutSourceCodeKey] ON [dbo].[CampaignParticipation] ([OptOutSourceCodeKey]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_CampaignParticipation_RespondentUserKey] ON [dbo].[CampaignParticipation] ([RespondentUserKey]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_CampaignParticipation_ResponseTypeCode] ON [dbo].[CampaignParticipation] ([ResponseTypeCode]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_CampaignParticipation_UpdatedByUserKey] ON [dbo].[CampaignParticipation] ([UpdatedByUserKey]) ON [PRIMARY]
GO
ALTER TABLE [dbo].[CampaignParticipation] ADD CONSTRAINT [FK_CampaignParticipation_CampaignMain] FOREIGN KEY ([CampaignKey]) REFERENCES [dbo].[CampaignMain] ([CampaignKey])
GO
ALTER TABLE [dbo].[CampaignParticipation] ADD CONSTRAINT [FK_CampaignParticipation_ResponseTypeRef] FOREIGN KEY ([ResponseTypeCode]) REFERENCES [dbo].[ResponseTypeRef] ([ResponseTypeCode])
GO
ALTER TABLE [dbo].[CampaignParticipation] ADD CONSTRAINT [FK_CampaignParticipation_SourceCode] FOREIGN KEY ([OptOutSourceCodeKey]) REFERENCES [dbo].[SourceCode] ([SourceCodeKey])
GO
ALTER TABLE [dbo].[CampaignParticipation] ADD CONSTRAINT [FK_CampaignParticipation_UserMain_CreatedBy] FOREIGN KEY ([CreatedByUserKey]) REFERENCES [dbo].[UserMain] ([UserKey])
GO
ALTER TABLE [dbo].[CampaignParticipation] ADD CONSTRAINT [FK_CampaignParticipation_UserMain_UpdatedBy] FOREIGN KEY ([UpdatedByUserKey]) REFERENCES [dbo].[UserMain] ([UserKey])
GO
Uses
Used By